clear
set matsize 11000

********************************************************************************
* Read-in panel data
use "./data/fomc_panel_b", clear

*drop US
drop if ccode==49

********************************************************************************
*Identify large mpu changes
egen date_tag = tag(date)
tab date if mpu10_2day>1.2 & date_tag
tab date if mpu10_2day<-2.3 & date_tag

gen 	mpu_flg = 0
replace mpu_flg = 1 if (mpu10_2day>=1.2|mpu10_2day<=-2.3) & mpu10_2day!=.

gen 	mpu_riser = 1 if mpu10_2day>0 & mpu_flg==1
gen 	mpu_faller = 1 if mpu10_2day<0 & mpu_flg==1

bysort mpu_riser: sum mpu10_2day

bysort mpu_faller: sum mpu10_2day

********************************************************************************

*Pooled coefficients
foreach k in yield10y {

	
	***Advanced coefficients***
	
	*MPS/MPU
		* Full Sample
			gen `k'_mps_full_adv 		= .
			gen `k'_mpu_full_adv 		= .

	capture noisily quietly: reghdfe `k'_2day_std mps_2day mpu10_2day if advanced==1, noabsorb cluster(ccode time)
	capture noisily replace `k'_mps_full_adv 		= _b[mps_2day]
	capture noisily replace `k'_mpu_full_adv		= _b[mpu10_2day]


	***EME coefficients***

	*MPS/MPU
		* Full Sample
			gen `k'_mps_full_eme 		= .
			gen `k'_mpu_full_eme 		= .
			

	capture noisily quietly: reghdfe `k'_2day_std mps_2day mpu10_2day if advanced==0, noabsorb cluster(ccode time)
	capture noisily replace `k'_mps_full_eme 		= _b[mps_2day]
	capture noisily replace `k'_mpu_full_eme		= _b[mpu10_2day]
	
	***Pooled coefficients***

	*MPS/MPU
		* Full Sample
			gen `k'_mps_full 		= .
			gen `k'_mpu_full 		= .
			

	capture noisily quietly: reghdfe `k'_2day_std mps_2day mpu10_2day, noabsorb cluster(ccode time)
	capture noisily replace `k'_mps_full		= _b[mps_2day]
	capture noisily replace `k'_mpu_full		= _b[mpu10_2day]
	

}

foreach k in yield10y {

	preserve

	collapse (mean) mpu_flg mpu_riser mpu_faller `k'_2day_std mps_2day mpu10_2day `k'_mps_full_adv `k'_mpu_full_adv `k'_mps_full_eme `k'_mpu_full_eme, by(advanced date)

	keep if mpu_flg==1

	gen 	mps_effect = mps_2day * `k'_mps_full_adv if advanced==1
	replace mps_effect = mps_2day * `k'_mps_full_eme if advanced==0

	gen 	mpu_effect = mpu10_2day * `k'_mpu_full_adv if advanced==1
	replace mpu_effect = mpu10_2day * `k'_mpu_full_eme if advanced==0

	label var `k'_2day_std "Total"
	label var mps_effect "MPS"
	label var mpu_effect "MPU"

	levelsof date, local(dates)
	foreach date of local dates {
		label define T `date' `"`= strofreal(`date',"%td")'"', add
	}
	label values date T

	label define adv 0 EME 1 Advanced
	label values advanced adv

	graph hbar `k'_2day_std mps_effect mpu_effect if advanced==1 & mpu_riser==1, over(date) legend(label(1 "Total") label(2 "MPS") label(3 "MPU")) legend(ring(0) position(2) bmargin(large)) ylabel(-2(1)3, labsize(med)) bar(1, fcolor(white) lcolor(black)) bar(2, fcolor(black) lcolor(black)) bar(3, fcolor(gs12) lcolor(black))
	graph export "tables\figureA3_PanelA.pdf", replace	

	graph hbar `k'_2day_std mps_effect mpu_effect if advanced==1 & mpu_faller==1, over(date) legend(off) ylabel(-2(1)3, labsize(med)) bar(1, fcolor(white) lcolor(black)) bar(2, fcolor(black) lcolor(black)) bar(3, fcolor(gs12) lcolor(black))
	graph export "tables\figureA3_PanelB.pdf", replace	

	graph hbar `k'_2day_std mps_effect mpu_effect if advanced==0 & mpu_riser==1, over(date) legend(off) ylabel(-2(1)3, labsize(med)) bar(1, fcolor(white) lcolor(black)) bar(2, fcolor(black) lcolor(black)) bar(3, fcolor(gs12) lcolor(black))
	graph export "tables\figureA3_PanelC.pdf", replace	

	graph hbar `k'_2day_std mps_effect mpu_effect if advanced==0 & mpu_faller==1, over(date) legend(off) ylabel(-2(1)3, labsize(med)) bar(1, fcolor(white) lcolor(black)) bar(2, fcolor(black) lcolor(black)) bar(3, fcolor(gs12) lcolor(black))
	graph export "tables\figureA3_PanelD.pdf", replace	
	
	restore

}

